package com.itheima.d1_charset;

import jdk.swing.interop.SwingInterOpUtils;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * 目标：掌握如何使用Java代码完成对字符的编码和解码。
 */
public class Test {
    public static void main(String[] args) throws Exception {
        // 1、编码
        String str1 = "我a你";
        byte[] bytes = str1.getBytes();
        System.out.println(Arrays.toString(bytes));

       /* for (byte aByte : bytes) {
            System.out.println(Integer.toBinaryString(aByte));
        }*/
        // ASCII GBK UTF-8
        byte[] gbks = str1.getBytes("GBK");
        System.out.println(Arrays.toString(gbks));

        // 2、解码
        String str2 = new String(bytes);
        System.out.println(str2);

        String str3 = new String(gbks, "GBK");
        System.out.println("str3 = " + str3);
    }
}

